package cn.com.smart.module.system.xRepDataset.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.com.smart.framework.aspectj.lang.annotation.Log;
import cn.com.smart.framework.aspectj.lang.enums.BusinessType;
import cn.com.smart.module.system.xRepDataset.domain.XRepDataset;
import cn.com.smart.module.system.xRepDataset.service.IXRepDatasetService;
import cn.com.smart.framework.web.controller.BaseController;
import cn.com.smart.framework.web.page.TableDataInfo;
import cn.com.smart.framework.web.domain.AjaxResult;
import cn.com.smart.common.utils.poi.ExcelUtil;

/**
 * 数据集信息操作处理
 * 
 * @author xman
 * @date 2019-07-05
 */
@Controller
@RequestMapping("/system/xRepDataset")
public class XRepDatasetController extends BaseController
{
    private String prefix = "system/xRepDataset";
	
	@Autowired
	private IXRepDatasetService xRepDatasetService;
	
	@RequiresPermissions("system:xRepDataset:view")
	@GetMapping()
	public String xRepDataset()
	{
	    return prefix + "/xRepDataset";
	}
	
	/**
	 * 查询数据集列表
	 */
	@RequiresPermissions("system:xRepDataset:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(XRepDataset xRepDataset)
	{
		startPage();
        List<XRepDataset> list = xRepDatasetService.selectXRepDatasetList(xRepDataset);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出数据集列表
	 */
	@RequiresPermissions("system:xRepDataset:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(XRepDataset xRepDataset)
    {
    	List<XRepDataset> list = xRepDatasetService.selectXRepDatasetList(xRepDataset);
        ExcelUtil<XRepDataset> util = new ExcelUtil<XRepDataset>(XRepDataset.class);
        return util.exportExcel(list, "xRepDataset");
    }
	
	/**
	 * 新增数据集
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存数据集
	 */
	@RequiresPermissions("system:xRepDataset:add")
	@Log(title = "数据集", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(XRepDataset xRepDataset)
	{		
		return toAjax(xRepDatasetService.insertXRepDataset(xRepDataset));
	}

	/**
	 * 修改数据集
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		XRepDataset xRepDataset = xRepDatasetService.selectXRepDatasetById(id);
		mmap.put("xRepDataset", xRepDataset);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存数据集
	 */
	@RequiresPermissions("system:xRepDataset:edit")
	@Log(title = "数据集", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(XRepDataset xRepDataset)
	{		
		return toAjax(xRepDatasetService.updateXRepDataset(xRepDataset));
	}
	
	/**
	 * 删除数据集
	 */
	@RequiresPermissions("system:xRepDataset:remove")
	@Log(title = "数据集", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(xRepDatasetService.deleteXRepDatasetByIds(ids));
	}
	
}
